import {
	getUserComments
} from '../../../../api/weddingMan/index'

const app = getApp()
Page({
	data: {
		commentList: [],
		totalPage: 1,
		showCount: 10,
		currentPage: 1,
		loadMoreText: "加载中...",
		showLoadMore: false,
		isLabelMore: false,
		labelList: [],
		name: '',
		userId: '',
		commentsLen: 0
	},
	onLoad: function(options) {
		this.setData({
			name: options.name,
			userId: options.userId
		})
		wx.setNavigationBarTitle({
			title: `${this.data.name}的评价`
		})
		this.initComments();
	},
	onReachBottom() {
		
		const {
			currentPage,
			totalPage
		} = this.data
		if (currentPage < totalPage) {
			this.setData({
				currentPage: this.data.currentPage + 1
			})
			setTimeout(() => {
				this.getComments();
			}, 300);
		} else {
			this.setData({
				loadMoreText: '没有更多数据了!'
			})
		}
		this.setData({
			showLoadMore: true
		})
	},
	onPullDownRefresh() {
		;
		this.initComments();
	},
	toggleLableMore() {
		this.setData({
			isLabelMore: !this.data.isLabelMore
		})
	},
	initComments() {
		this.setData({
			commentList: [],
			currentPage: 1,
			totalPage: 1
		})
		this.getComments();
	},
	getComments() {
		getUserComments({
			showCount: this.data.showCount,
			currentPage: this.data.currentPage,
			userId: this.data.userId,
		}).then((res) => {
			;
			let list = res.data.list || [];
			this.setData({
				totalPage: res.data.totalPage || 1,
				commentsLen: res.data.totalPage,
				labelList: res.data.labelInfo.labelList,
				commentList: this.data.commentList.concat(list),
				showLoadMore: false
			})
			wx.stopPullDownRefresh();
		}).catch((err) => {
			;
		})
	}
});
